package com.spyx.product.controller;


import com.atyx.spyx.model.product.Attr;
import com.atyx.spyx.model.product.AttrGroup;
import com.spyx.product.service.AttrService;
import com.spyx.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品属性 前端控制器
 * </p>
 *
 * @author yhp
 * @since 2024-05-15
 */
@RestController
@RequestMapping("/admin/product/attr")
@Api(tags = "属性管理")
//@CrossOrigin
public class AttrController {

    @Autowired
    private AttrService attrService;

    @ApiOperation("根据属性分组id查询属性列表")
    @GetMapping("/{groupId}")
    public Result groupId(@PathVariable("groupId")Integer groupid){

       List<Attr> list= attrService.getAttrList(groupid);

        return Result.ok(list);
    }
    @ApiOperation("新增属性")
    @PostMapping("/save")
    public Result save(@RequestBody Attr attr){
        attrService.save(attr);
        return Result.ok();
    }
    @ApiOperation("主键查询")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id")Integer id){
        Attr attr = attrService.getById(id);
        return Result.ok(attr);
    }
    @ApiOperation("更新属性")
    @PutMapping("/update")
    public Result update(@RequestBody Attr attr){
        attrService.updateById(attr);
        return Result.ok();
    }
    @ApiOperation("删除属性")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable("id")Integer id){
        attrService.removeById(id);
        return Result.ok();
    }
    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result removeRows(@RequestBody List<Integer> idList){
        attrService.removeByIds(idList);
        return Result.ok();
    }

}

